/**
 * 
 */
package il.ac.technion.wiki.api.expressions;


import il.ac.technion.wiki.api.search.Hit;
import il.ac.technion.wiki.api.wikidocument.WikiDocument;
import il.ac.technion.wiki.impl.search.WikiIndexSearcher;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;

/**
 * @author moshemal
 *
 */
public class AndOpTest {

	/**
	 * Test method for {@link il.ac.technion.wiki.api.expressions.AndOp#evaluate(il.ac.technion.wiki.api.search.IndexSearcher)}.
	 */
	@Test
	public void testEvaluate() {
		WikiIndexSearcher mis = new WikiIndexSearcher();
		createDocs(mis);
		AndOp and = new AndOp();
		and.setElements(new Term("b"), new Term("c"));
		List<Hit> hits = and.getHits(mis);
		Hit hit = hits.get(0);
		Assert.assertEquals("3", hit.docTitle);
		hit = hits.get(1);
		Assert.assertEquals("2", hit.docTitle);
		hit = hits.get(2);
		Assert.assertEquals("1", hit.docTitle);
		and.setElements(new Term("new"), new Term("york"));
		hits = and.getHits(mis);
		hit = hits.get(0);
		Assert.assertEquals("7", hit.docTitle);
	}
	
	private void createDocs(WikiIndexSearcher mis){
		mis.addDocument(new WikiDocument("1" , "a b c d d b"));
		mis.addDocument(new WikiDocument("2" , "b b b c "));
		mis.addDocument(new WikiDocument("3" , "c c c b b"));
		mis.addDocument(new WikiDocument("4" , "d d d c"));
		mis.addDocument(new WikiDocument("5" , "new york"));
		mis.addDocument(new WikiDocument("6" , "new new york"));
		mis.addDocument(new WikiDocument("7" , "new york, new york"));
	}
}
